package cn.leven.service.impl;

import cn.leven.dao.UserDao;
import cn.leven.dao.impl.UserDaoImpl;
import cn.leven.domain.UserInfo;
import cn.leven.service.UserService;

import java.util.List;

public class UserServiceImpl implements UserService {
    private UserDao dao = new UserDaoImpl();
    @Override
    public List<UserInfo> findAll() {
        // 调用dao完成查询
        return dao.findAll();
    }

    @Override
    public UserInfo login(UserInfo userInfo) {
        return dao.findUser(userInfo.getUsername(),userInfo.getPassword());
    }

    @Override
    public void deleteUser(String id) {
        dao.deleteUser(Integer.parseInt(id));
    }

    @Override
    public void addUser(UserInfo userInfo) {
        dao.addUser(userInfo);
    }

    @Override
    public void updateUser(UserInfo user) {
        dao.updateUser(user);
    }

    @Override
    public void deleteSelectUser(String[] ids) {
        if(ids!=null&&ids.length>0){
            for (String id : ids) {
                dao.deleteUser(Integer.parseInt(id));
            }
        }
    }

    public UserInfo findUser(String id) {
        return dao.findUser(Integer.parseInt(id));
    }
}
